<extend name="Base/common"/>
<block name="Content">
    <div class="am-cf am-padding-top">
        <div class="am-fl am-cf">
            <i class="am-icon-file"></i>
            <strong class="am-text-primary am-text-lg">{$dictModel['dict_name']}---->子类管理</strong>
        </div>
        <hr data-am-widget="divider" style="" class="am-divider am-divider-default" />
    </div>
    <form class="am-form-horizontal" method="post" action="{:U('Dictionary/addEnum')}">
        <div class="am-fr am-padding-right">
            隶属分类：<a>{$dictModel['dict_name']}</a>
        </div>
        分类名称: <input type="text" placeholder="输入分类名" name="enum_name" required/><input type="hidden" value="{$dict_id}" name="dict_id"/>
        <div class="am-btn-group am-btn-group-xs">
            <button type="submit" class="am-btn am-btn-success ajax-post" target-form="am-form-horizontal">
                <span class="am-icon-plus"></span>&nbsp;新增
            </button>
            <button type="button" class="am-btn am-btn-warning ajax-post confirm" url="{:U('delEnum')}" target-form="ck">
                <span class="am-icon-trash-o"></span>
                删除
            </button>
            <a class="am-btn am-btn-secondary" href="{:U('Dictionary/index')}" target-form="ck"><span class="am-icon-undo"></span>返回</a>
        </div>
        <hr data-am-widget="divider" class="am-divider am-divider-default" />
    </form>
    <table class="am-table am-table-striped am-table-hover table-main" id="table">
        <thead>
            <tr>
                <th class="table-check">
                    <input type="checkbox" class="checkAll" />
                </th>
                <th class="table-title" style="width:20%">
                    枚举名 
                </th>
                <th class="table-title" style="width:20%">
                    字典标识
                </th>
                <th class="table-type" style="width:15%">
                    字典值
                </th>
                <th class="table-type" style="width:15%">
                    排序号
                </th>
                <th class="table-set" style="width:20%">
                    操作
                </th>
            </tr>
        </thead>
        <tbody>
            <notempty name="dictlist">
                <foreach name="dictlist" item="dictEnum">
                    <tr>
                        <td>
                            <input type="checkbox" value="{$dictEnum.enum_id}" name="enum_ids[]" class="ck"/>
                        </td>
                        <td>
                            <input type="text" value="{$dictEnum.enum_name}" name="enum_name" required/>
                        </td>
                        <td>
                            {$dictModel['dict_group']}
                        </td>
                        <td>
                            {$dictEnum.enum_value}
                        </td>
                        <td>
                            <input type="number" value="{$dictEnum.sort_no}" name="sort_no" min="1" max="100" step="1" style="width:100px"/>
                        </td>
                        <td>
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a class="am-btn am-btn-default am-btn-xs am-text-secondary" name='update'><span class="am-icon-pencil-square-o"></span>更新</a>
                                    <a class="am-btn am-btn-default am-btn-xs am-text-danger confirm ajax-get" href="{:U('delEnum?enum_ids='.$dictEnum['enum_id'])}"><span class="am-icon-pencil-square-o"></span>删除</a>
                                </div>
                            </div>
                        </td>
                    </tr>
                </foreach>
                <else/>
                <td colspan="6" class="text-center">
                    暂时还没有内容! 
                </td>
            </notempty>
        </tbody>
    </table>
</block>
<block name="script">
    <script type="text/javascript">
        
        $(function(){
            //修改子类型
            $("#table").each(function(){
                $("a[name=update]").click(function(){
                    var $thisTD = $(this).parents("tr").find("td:eq(1)");//下标0开始的
                    name = $thisTD.find("input").val();
                    var $thisTDK = $(this).parents("tr").find("td:eq(4)");
                    no = $thisTDK.find("input").val();
                    var $thisID = $(this).parents("tr").find("td:eq(0)")
                    id = $thisID.find(".ck").val();
                    var reg = new RegExp("^\\d+$");
                    var reg1 = new RegExp("^[\u0391-\uFFE5]+$");
                    if (!reg.test(no)) {
                        alert("请输入数字！");
                        return;
                    }
                    else {
                        if (!reg1.test(name)) {
                            alert("枚举名只能为中文！");
                            return;
                        }
                        $.getJSON("{:U('Dictionary/addEnum')}", {
                            dictEnum_id: id,
                            enum_name: name,
                            sort_no: no
                        }, function(json){
                        
                            if (json == 1) {
                                updateAlert('操作成功~', 'alert-success');
                                setTimeout(function(){
                                    $('#top-alert').find('button').click();
                                }, 1500);
                               // alert('操作成功');
                            }
                            else {
                                 updateAlert('操作失败~');
                                setTimeout(function(){
                                    $('#top-alert').find('button').click();
                                }, 1500);
                            }
                        });
                        
                    }
                    
                    
                    
                });
                
            });
        });
    </script>
</block>
